package com.xingdian.xingdianhulianserver.service.impl;

import com.github.pagehelper.PageHelper;
import com.xingdian.xingdianhulianserver.common.QueryObject;
import com.xingdian.xingdianhulianserver.common.ServerResponse;
import com.xingdian.xingdianhulianserver.mapper.CityMapper;
import com.xingdian.xingdianhulianserver.mapper.FirstTypeMapper;
import com.xingdian.xingdianhulianserver.mapper.ProjectJoinMapper;
import com.xingdian.xingdianhulianserver.mapper.SecTypeMapper;
import com.xingdian.xingdianhulianserver.service.IProjectJoin;
import com.xingdian.xingdianhulianserver.vo.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/* *
 * @Author H2SO4
 * @ClassName: ProjectJoinServiceImpl
 * @Description TODO
 * @Date 2019/12/27--10:05
 * */
@Controller
public class ProjectJoinServiceImpl implements IProjectJoin {
    @Autowired
    CityMapper cityMapper;
    @Autowired
    FirstTypeMapper firstTypeMapper;
    @Autowired
    SecTypeMapper secTypeMapper;
    @Autowired
    ProjectJoinMapper projectJoinMapper;

    @Override
    public ServerResponse findCitys() {
        return ServerResponse.createBySuccess(cityMapper.findCitys());
    }

    @Override
    public ServerResponse findprojectjoin(QueryObject queryObject) {
        int total = projectJoinMapper.countInfo(queryObject);
        PageHelper.startPage((queryObject.getCurrentPage()/queryObject.getPageSize()+1),queryObject.getPageSize());
        List<ProjectJoin> projectJoins = projectJoinMapper.findinfo(queryObject);
        Map<String,Object> map = new HashMap<>();
        map.put("projectJoins",projectJoins);
        map.put("total",total);
        return ServerResponse.createBySuccess(map);
    }

    @Override
    public int addprojectjoin(ProjectJoin projectJoin) {
        return projectJoinMapper.insertSelective(projectJoin);
    }

    @Override
    public ServerResponse findLists() {
        List<City> list1 = cityMapper.findCitys();
        List<FirstType> list2 = firstTypeMapper.findFirstTypes();
        List<SecType> list3 = secTypeMapper.findSecType();
        Map<String,Object> map = new HashMap<>();
        map.put("list1",list1);
        map.put("list2",list2);
        map.put("list3",list3);
        return ServerResponse.createBySuccess(map);
    }

    //根据id查询品牌信息
    @Override
    public ProjectJoin findById(Integer id) {
        return projectJoinMapper.selectByPrimaryKey(id);
    }

    //查询修改页面所需信息
    @Override
    public Map<String,Object> findList(Integer id) {
        List<City> list1 = cityMapper.findCitys();
        List<FirstType> list2 = firstTypeMapper.findFirstTypes();
        List<SecType> list3 = secTypeMapper.findSecType();
        ProjectJoin projectJoin = projectJoinMapper.selectByPrimaryKey(id);
        Map<String,Object> map = new HashMap<>();
        map.put("list1",list1);
        map.put("list2",list2);
        map.put("list3",list3);
        map.put("projectJoin",projectJoin);
        return map;
    }

    //修改品牌
    @Override
    public void updateprojectjoin(ProjectJoin projectJoin) {
        projectJoinMapper.updateByPrimaryKeySelective(projectJoin);
    }

    //逻辑删除品牌
    @Override
    public void delprojectjoin(Integer id) {
        projectJoinMapper.delprojectjoin(id);
    }
}
